﻿using AntdUI;
using Model;
using PrintLabel.Tools;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 纺织贸易管理系统;

namespace PrintLabel.View
{
    public partial class FabricSelectFrm : AntdUI.Window 
    {
        public InspectionNoticeNeedDetail selectdb { get; set; }
        private string danhao { get; set; }
        public FabricSelectFrm(string docnum)
        {
            InitializeComponent();
            table1.AutoSizeColumnsMode = AntdUI.ColumnsMode.Fill; 
            var btns = new CellLink[] { new CellButton("修改") };
            table1.Columns = new AntdUI.ColumnCollection()
            {  
                new AntdUI.Column ("NeedNum","需求数"),
                new AntdUI.Column ("FinishNum","完成数"),
                 new AntdUI.Column ("OrderNum","订单号"),
                  new AntdUI.Column ("ContractNum","合同号"),
                 new AntdUI.Column ("color","颜色"),
                 new AntdUI.Column ("Kuanhao","款号"), 
                new AntdUI.Column ("sampleNum","编号"),
                new AntdUI.Column ("sampleName","品名"),
                 new AntdUI.Column ("CustomerPingMing","客户品名"),  
                new AntdUI.Column ("CustomerColorNum","客户颜色"),
                  new AntdUI.Column ("Unit","单位"),
            };
            txtdanhao.Text = docnum;
            QueryFabric(1);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            QueryFabric(1);
        }
        private void QueryFabric(int current)
        {
            if (!string.IsNullOrEmpty(txtdanhao.Text))
            {
                var items=dbContext.dbcontext.Queryable<InspectionNoticeNeedDetail>().Where(x => x.InspectionNoticeNum == txtdanhao.Text).ToList();
                table1.DataSource = items;
               
                if (items.Count == 0)
                {
                    ShowMessage.ShowErrorMessagebox(this, $"没有找到这个任务单{txtdanhao.Text}的任何信息");
                }
            }
        }

        private void txtbianhao_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter) {
                QueryFabric(1);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if(table1.SelectedIndex>=0)
            {
                var dbs= table1.DataSource as List<InspectionNoticeNeedDetail>;
                selectdb = dbs[table1.SelectedIndex - 1];
                this.Close();
            }
        }

        private void table1_CellDoubleClick(object sender, TableClickEventArgs e)
        {
            var items=table1.DataSource as List<InspectionNoticeNeedDetail>;
            selectdb = items[table1.SelectedIndex - 1];
            this.Close();
        }

        private void FabricSelectFrm_Load(object sender, EventArgs e)
        {
            txtdanhao.Focus();
        }

        private void txtdanhao_Click(object sender, EventArgs e)
        {
            KeyboardHelper.ShowKeyboard("LettersAndNumberNoFunctionKeys", "输入");
        }
    }
}
